<template>
	<view class="mine-page-box">
		<image class="mine-page" src="@/static/mine/mine_bg.png"></image>
		<u-navbar title="课后延时教学平台" bgColor="transparent" :placeholder="true">
			<view slot="left"></view>
		</u-navbar>
		<view class="user-info-box">
			<view class="user-avatar">
				<image :src="userInfo.avatar" mode="aspectFill" v-if="isLogin&&userInfo.avatar"></image>
				<image src="@/static/default_avatar.png" mode="aspectFill" v-else></image>
			</view>
			<view class="user-info">
				<view class="user-name" v-if="isLogin">{{ userInfo.nickname || '未填写' }}</view>
				<view class="user-name" v-else>暂未登录</view>
				<view class="user-id" v-if="isLogin">ID: {{ userInfo.id }}</view>
				<view class="to-login" v-if="!isLogin" @click="navigatorPage('/pages/login/login')">
					<view>去登录</view>
					<image class="arrow-right" src="@/static/mine/mine_right.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="user-menu-box">
			<view class="user-menu">
				<view class="user-menu-item" @click="navigatorPage('/pages/myAttendance/myAttendance',true)">
					<view class="item-left">
						<image src="@/static/mine/menu_1.png" mode="aspectFill"></image>
						<view>我的上课考勤</view>
					</view>
					<view class="item-right">
						<image src="@/static/mine/mine_right2.png" mode="aspectFill"></image>
					</view>
				</view>
				<view class="user-menu-item" @click="navigatorPage('/pages/attendanceList/attendanceList',true)">
					<view class="item-left">
						<image src="@/static/mine/menu_2.png" mode="aspectFill"></image>
						<view>去考勤</view>
					</view>
					<view class="item-right">
						<image src="@/static/mine/mine_right2.png" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</view>
    <view class="login-out-box" v-if="isLogin">
      <view class="login-out" @click="userLogout">退出登录</view>
    </view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				
			}
		},
		computed: mapGetters(['isLogin','userInfo']),
		methods: {
      //页面跳转
      navigatorPage(page, auth = false) {
        if (auth && !this.isLogin) {
          this.$Tips("/pages/login/login")
        } else {
          this.$Tips(page)
        }
      },
      userLogout(){
        uni.clearStorageSync()
        this.$store.commit('LOGOUT')
        this.$Toast('退出登录成功')
      }
		}
	}
</script>

<style lang="scss" scoped>
	.mine-page-box {
		min-height: 100vh;
		background: #f5f6fa;

		.mine-page {
			width: 100%;
			height: 406rpx;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 10;
		}

		.user-info-box {
			position: relative;
			margin-top: 50rpx;
			width: 100%;
			display: flex;
			align-items: center;
			padding: 0 30rpx;
			box-sizing: border-box;
			z-index: 100;

			.user-avatar {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.user-info {
				flex: 1;
				margin-left: 30rpx;

				.user-name {
					font-size: 32rpx;
					color: #333333;
					font-weight: bold;
				}

				.user-id {
					font-size: 28rpx;
					color: #222222;
					margin-top: 10rpx;
				}

				.to-login {
					display: flex;
					align-items: center;
					color: #0095F8;
					font-size: 28rpx;
					margin-top: 16rpx;
					image {
						width: 32rpx;
						height: 32rpx;
					}
				}
			}
		}

		.user-menu-box {
			width: 100%;
			position: absolute;
			top: 426rpx;
			z-index: 10;

			.user-menu {
				margin: 0 30rpx;

				.user-menu-item {
					display: flex;
					align-items: center;
					padding: 32rpx 42rpx;
					background: #ffffff;
					box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.01);
					border-radius: 24rpx;
					margin-bottom: 20rpx;

					.item-left {
						flex: 1;
						display: flex;
						align-items: center;

						image {
							width: 30rpx;
							height: 30rpx;
							margin-right: 28rpx;
						}

						view {
							font-size: 28rpx;
              font-weight: bold;
						}
					}

					.item-right {
						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}
			}
		}
    .login-out-box{
      width: 100%;
      position: absolute;
      bottom: 126rpx;
      left: 0;
      display: flex;
      justify-content: center;
      .login-out {
        font-size: 30rpx;
        color: #FFFFFF;
        display: flex;
        justify-content: center;
        align-items: center;
        width: 670rpx;
        height: 88rpx;
        background: #0095F8;
        box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0,149,248,0.5);
        border-radius: 44rpx;
      }
    }
	}
</style>